<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>事件循环</title>
</head>

<body>

</body>

</html>

<script>
    var p = new Promise(resolve => {
        console.log(4)
        resolve(5)
    });

    function fn1() {
        console.log(1)
    }

    function fn2() {
        setTimeout(() => {
            console.log(2)
        }, 0)
        fn1()
        console.log(3)
        p.then(resolve => {
            console.log(resolve)
        })
    }
    fn2()

    //执行结果 4,1,3,5,2
</script>